home *** CD-ROM | disk | FTP | other *** search
- Path: svnews.ubinet.ubs.com!ubszh!ubszh!jis
- From: jis@ubszh.net.ch (Johnston Ian (by ubsswop))
- Newsgroups: comp.lang.c++
- Subject: Re: Virtual Members: Difficult Question
- Date: 22 Jan 1996 10:09:21 GMT
- Organization: UBS
- Distribution: world
- Message-ID: <4dvnoh$rbd@ubszh.fh.zh.ubs.com>
- References: <4dmha6$80c@marlin.ssnet.com> <4doof9$hom@charnel.ecst.csuchico.edu> <4doss3$b1i@marlin.ssnet.com>
- NNTP-Posting-Host: nol2179.fh.zh.ubs.com
-
- In article <4doss3$b1i@marlin.ssnet.com>, helie@ssnet.com (Ray Helie) writes:
-
- [...]
-
- |> In a nutshell, I declared object of derived size, cast to the
- |> base, cast again to a parent class of base, cast back to base,
- |> tried to write a derived amount of data to the base class (as if
- |> it was an array of characters, starting at the object's address,
- |> which is the same way I wrote the information to begin with), and
- |> it dies on me when I do a virtual function call. The derived amount of
- |> space is there -- that's what I started with.
- |>
- |> So I don't think you understand my question, because I understand
- |> what you're saying, you are right under the circumstances you
- |> described, but I think you got the circumstances wrong...?
- |>
- |>
- |> If anyone else can help, I'd appreciate it. :)
-
- Well, it looks like you are overwriting the vtable ptr, and then when
- you call a virtual function you are going off to never-never land (because
- the pointer to the function in the vtable is corrupt).
-
- Your downcast from "parent of base" to "base" could be causing a problem, if
- you have multiple inheritance.
-
- I didn't see your original post, but you say you are "writing the
- information" starting "at the object's address". Let me guess: you are wriing
- the object out to disk or other external source, then trying to read it in?
-
- If that's the case, you just can't do it (reliably). The innards of an
- object with virtual functions are more than just the object's data members;
- there is also a pointer to a table of virtual functions (and a pointer
- to base classes with virtual inheritance) [at least, this is how objects
- are usually implemented].
-
- You just can't write out the pointer to a virtual function table to disk,
- read it aback, and expect to have things work. You wouldn't write the value
- of any other pointer out to disk, read it back, and expect it still to point
- to the same thing, would you?
-
- Ian
-
-